#pragma once

#include "Windows.UI.Xaml.Media.DXInterop.h"
#include "IEffectDescription.h"
#include "Effect.h"

using namespace Windows::Storage::Streams;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::Foundation::Collections;
using namespace Platform::Collections;

namespace DeForm
{
	public enum struct CompressionMode {PNG, JPG};

	public ref class ImageManipulator sealed
	{
		// Members
		std::vector<Effect>					m_effectDescriptions;
		ComPtr<ID2D1Effect>					m_source;
		SurfaceImageSource^					m_surfaceImageSource;		
		ComPtr<ISurfaceImageSourceNative>	m_nativeSurfaceImageSource;
		ComPtr<ID2D1Image>					m_d2dImage;
		UINT								m_frameWidth;
		UINT								m_frameHeight;

		// Methods
		ComPtr<IWICFormatConverter> GetConverter(IRandomAccessStream^ sourceStream);

	public:
		ImageManipulator(IRandomAccessStream^ sourceStream);
		virtual ~ImageManipulator();

		void AddEffectDescription(IEffectDescription ^effectDescription);
		void RemoveEffectDescription(IEffectDescription ^effectDescription);
		void ClearEffectDescriptions();

		SurfaceImageSource^ CreateSurfaceImageSource();
		void DeleteSurfaceImageSource();

		void Manipulate(bool updateSurfaceImageSource);

		void SaveToStream(IRandomAccessStream^ destinationStream, CompressionMode compressionMode);
		void UpdateSurfaceImageSource();
	};
}

